﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartWMS.Domain.Base;

namespace SmartWMS.Server.Repository
{
    public interface IRepository<T> where T : KeyEntity
    {
        /// <summary>
        /// 获取所有的数据
        /// </summary>
        /// <returns></returns>
        Task<List<T>> GetAllListAsync();

        /// <summary>
        /// 获取集合的Query
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetListQuery();

        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<T> GetEntityByIdAsync(KeyEntity key);

        /// <summary>
        /// 返回总数
        /// </summary>
        /// <returns></returns>
        int GetCount();

        /// <summary>
        /// 插入单条数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> InsertAsync(T entity);

        /// <summary>
        /// 批量插入数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> InsertAsync(List<T> values);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(T entity);
        /// <summary>
        /// 批量编辑
        /// </summary>
        /// <param name="entities">要编辑的实体集合</param>
        /// <returns>异步操作结果</returns>
        Task<int> UpdateRangeAsync(List<T> entities);

        /// <summary>
        /// 删除单条数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeleteByIdAsync(KeyEntity key);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(List<T> values);

        /// <summary>
        /// 执行sql语句，返回受影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        int ExecuteSql(string sql);

        /// <summary>
        /// 使用SQL脚本查询
        /// </summary>
        /// <typeparam name="T"> T为数据库实体</typeparam>
        /// <returns></returns>
        IQueryable<T> FromSql(string sql, params object[] parameters);


        /// <summary>
        /// 单个逻辑删除
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<int> DelState(KeyEntity key);

        Task<int> AddRolePermissionAsync(int rid, string pid);

        Task<List<int>> SelRolePermissionAsync(int rid);
    }
}
